package terra.util;

import java.util.Random;

public class MathUtil {

	public static Random rnd = new Random();

	public static double distance(float x1, float y1, float w1, float h1,
			float x2, float y2, float w2, float h2) {
		float dx = (x1 + w1 / 2) - (x2 + w2 / 2);
		float dy = (y1 + h1 / 2) - (y2 + h2 / 2);
		return Math.sqrt((dx * dx) + (dy * dy));
	}

	public static float constrain(float input, float min, float max) {
		if (input < min)
			return min;
		if (input > max)
			return max;
		return input;
	}
	

	public static float getRndFloat(float min, float max) {
		if (min == max)
			return min;
		return min + rnd.nextFloat() * (max - min);
	}

	public static int getRndInt(int min, int max) {
		if (min == max)
			return min;
		return min + rnd.nextInt(max - min);
	}

	public static long getRndLong(long min, long max) {
		if (min == max)
			return min;
		return min + rnd.nextInt((int) (max - min));
	}
}
